﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Calendar.aspx.cs" Inherits="AiRiZu.User.Calendar" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>
	爱日租—全球最时尚、最具先锋概念的房屋日租、短租服务网站！
</title>
<meta content="爱日租,日租,短租,租房,家庭公寓,自助公寓,家庭旅馆,旅游" name="keywords"/>
<meta content="爱日租是国内首家专注房屋短期租赁的信息发布和在线交易的网站，为房主和租户搭建起最值得信赖的沟通和交易平台" name="description"/>

<link rel="stylesheet" href="css/css.css" />
<link rel="stylesheet" href="css/howitworks.css" />
<link rel="stylesheet" href="css/common.css" />
<link rel="stylesheet" href="css/pixie.css" />
<link rel="stylesheet" href="css/dashboard.css" />
<link rel="stylesheet" href="css/search.css" />
<link rel="stylesheet" href="css/voucher.css" />
<link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon" />

<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery-ui.min.js"></script>
<script type="text/javascript" src="js/jquery.imgareaselect.min.js"></script>
<script type="text/javascript" src="js/application6.js"></script>
<script type="text/javascript" src="js/home.js"></script>
<script type="text/javascript" src="js/translate.js"></script>
<script type="text/javascript" src="js/s_code.js?vid=1"></script>
<script type='text/javascript' src='js/fullcalendar.min.js'></script>
<script type='text/javascript' src='js/DateTimeUtil.js'></script>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta name="layout" content="main"/>


<style type="text/css">
#loading {
		position: absolute;
		top: 5px;
		right: 5px;
		}
</style>
<script type="text/javascript">
$(document).ready(function() {
	var eventSource;
	var date = new Date();
	var d = date.getDate();
	var m = date.getMonth();
	var y = date.getFullYear();
	var rId = $('#selectedRoom').val()
	var calendar = $('#fullcalendar').fullCalendar({
		
		weekends:true,
	
		//theme: true,
		header:{
			left:'prevYear,nextYear',
			center:'title',
			right:'prev,next'
		},
		editable: true,
		disableDragging:true,
		disableResizing:true,
		selectable: true,
		selectHelper: true,
		monthNames:["一月","二月","三月",
		    		"四月","五月","六月",
		    		"七月","八月","九月",
		    		"十月","十一月","十二月"],
		dayNamesShort:["星期日", "星期一","星期二",
		       		"星期三","星期四","星期五",
		       		"星期六"],
		viewDisplay:function(view){
			var vStart = view.visStart;
			var vEnd = view.visEnd;
//			eventSource = "handler/Calendar.ashx?viewStartDate=" + $.fullCalendar.formatDate(vStart, 'MM/dd/yyyy') + "&viewEndDate=" + $.fullCalendar.formatDate(vEnd, 'MM/dd/yyyy') + "&roomId=" + $('#selectedRoom').val();
			var between = daysBetween($.fullCalendar.formatDate(vStart, 'yyyy-MM-dd'),$.fullCalendar.formatDate(date, 'yyyy-MM-dd'))
			if(vStart < date && date < vEnd) {
			var $nodes= $("td[class*='fc-day']");
			$nodes.each(function(){
				if (this.id<=(between-1)){
				$(this).css({'background-color':'#e5e5e5'});
			}else if(this.id >(between-1)) {
				$(this).css({'background-color':'#e1fadf'});
			}
			});
			}else if(vEnd < date){
				$("td[class*='fc-day']").css({'background-color':'#e5e5e5'});
			}else if(vStart > date) {
				$("td[class*='fc-day']").css({'background-color':'#e1fadf'});
            }

            eventSource = "handler/Calendar.ashx?viewStartDate=" + $.fullCalendar.formatDate(vStart, 'MM/dd/yyyy') + "&viewEndDate=" + $.fullCalendar.formatDate(vEnd, 'MM/dd/yyyy') + "&roomId=" + $('#selectedRoom').val();
            $('#fullcalendar').fullCalendar('addEventSource', eventSource);
            $('#fullcalendar').fullCalendar('removeEventSource', eventSource);
			
		},
		select: function(startDate, endDate, allDay, jsEvent, view) {
			var cevents = calendar.fullCalendar('clientEvents');
			var sdate =$.fullCalendar.formatDate(date, 'MM/dd/yyyy')
			var sStartDate = $.fullCalendar.formatDate(startDate, 'MM/dd/yyyy')
			var sEnd = $.fullCalendar.formatDate(endDate, 'MM/dd/yyyy');
			var eventFlag = false;
			if(sStartDate >= sdate) {
			    eventFlag = true
			} else if (sStartDate < sdate && sEnd > sdate) {
			    sStartDate = sdate
			    eventFlag = true
			}
			if(eventFlag) {
				$("#tipInfo").html('')
			    $("#startDate").val(sStartDate);
			    $("#endDate").val(sEnd);
				
				$.ajax({
					   type: 'POST',
					   url: 'handler/GetPromotionFlag.ashx',
					   data: 'roomId=' + $("#selectedRoom").val() + '&startDate=' + $.fullCalendar.formatDate(startDate, 'yyyy-MM-dd') + '&endDate=' + $.fullCalendar.formatDate(endDate, 'yyyy-MM-dd'),
					   success: function(msg){
					   	   if(msg == 'error') {
					   			$("#price").attr('readOnly', true);
					   			$("#modify").attr('disabled', true)
					   			$("#tipInfo").html('所选日期包含特价日期，特价期间不允许修改价格')
					        } else if (msg == "success") {
					   			$("#price").attr('readOnly', false);
					   			$("#modify").attr('disabled', false)
						   }
					   }
					 });
			    
			    $("#pop_box_edit").css("display","block");
			    $("#price").val('');
			}
			calendar.fullCalendar('unselect');
		},
		eventClick:function(calEvent, jsEvent, view) {
			
			if(calEvent.editable=="true") {
				$("#tipInfo").html('')
				var start = $.fullCalendar.formatDate(calEvent.start, 'MM/dd/yyyy');
				$("#startDate").val(start);
				$("#endDate").val(start);
				var isAvailable;
				calEvent.className=="unavailable"?isAvailable="true":isAvailable="false";

				$.ajax({
					   type: 'POST',
					   url: 'handler/GetPromotionFlag.ashx',
					   data: 'roomId=' + $("#selectedRoom").val() + '&startDate=' + $.fullCalendar.formatDate(calEvent.start, 'yyyy-MM-dd'),
					   success: function(msg) {
					       if (msg == 'error') {
					           $("#price").attr('readOnly', true);
					           $("#modify").attr('disabled', true)
					           $("#tipInfo").html('所选日期包含特价日期，特价期间不允许修改价格')
					       } else if (msg == "success") {
					           $("#price").attr('readOnly', false);
					           $("#modify").attr('disabled', false)
					       }
					   }
					 });
				
				$("#selectForm option[value='"+isAvailable+"']").attr("selected",true);
				$("#pop_box_edit").css("display","block");
			}else{

				//如果roomNumber > 1 设置此日期的房间可以编辑
				if(calEvent.canOrderRoom == 'true'){
					if(typeof calEvent.unavailable == 'undefined') calEvent.unavailable = true
					$("#tipInfo").html('')
					$("#modify").attr('disabled', false)
					$("#price").val(calEvent.title).attr('readOnly', false);
					
					var start = $.fullCalendar.formatDate(calEvent.start, 'MM/dd/yyyy');
					$("#startDate").val(start);
					$("#endDate").val(start);
					$("#price").val(calEvent.title.split('x')[0].replace(/\s/g, '')).attr('readOnly', true);
					$("#selectForm option[value='"+calEvent.unavailable+"']").attr("selected",true);
					$("#pop_box_edit").css("display","block");
					
					return ;
				}

			} 	
		},
		loading: function(bool) {
			if (bool) $('#loading').show();
			else $('#loading').hide();
		}
	});
	
});

function changeSelectedRoom(roomID, roomTitle) {
	var view = $('#fullcalendar').fullCalendar('getView')
	var vStart = view.visStart;
	var vEnd = view.visEnd;
	eventSource = "handler/Calendar.ashx?viewStartDate=" + $.fullCalendar.formatDate(vStart, 'MM/dd/yyyy') + "&viewEndDate=" + $.fullCalendar.formatDate(vEnd, 'MM/dd/yyyy') + "&roomId=" + $('#selectedRoom').val();
	$('#fullcalendar').fullCalendar('removeEventSource', eventSource);
	$("#selectedRoom").val(roomID);
	changeCssWhenChangeSelectedRoom(roomID);
	eventSource = "handler/Calendar.ashx?viewStartDate=" + $.fullCalendar.formatDate(vStart, 'MM/dd/yyyy') + "&viewEndDate=" + $.fullCalendar.formatDate(vEnd, 'MM/dd/yyyy') + "&roomId=" + $('#selectedRoom').val();
	$('#fullcalendar').fullCalendar('addEventSource', eventSource);
	$('#fullcalendar').fullCalendar('removeEventSource', eventSource);
	document.getElementById('roomTitleId').innerHTML = '日历 - ' + roomTitle;
}

function changeCssWhenChangeSelectedRoom(roomId) {
	$("li").each(function() { $(this).removeClass('selected')});
	$("#"+roomId).addClass('selected');
}

</script>


<script type="text/javascript">

//$(document).ready(function(){
//        opts = {};
//        AirbnbHomePage.init(opts);
//    });

function addEventHandler(target, type, func) { 
    if (target.addEventListener) 
        target.addEventListener(type, func, false); 
    else if (target.attachEvent) 
        target.attachEvent("on" + type, func); 
    else target["on" + type] = func; 
} 
//addEventHandler(document, 'scroll', function() {
//	document.getElementById('list_loading').style.top = $('body').scrollTop() + 'px';
//});

function shiftLanguage(lang, country) {
	$.ajax({
		   type: "POST",
		   url: "/ajax/versionInternationalize",
		   data: 'lang=' + lang + '&country=' + country,
		   success: function(msg){
		   	   if(msg == 'success') {
		   	   	   window.location.reload(true);
		   	   }
		   }
		 });
}

//$(document).bind('click',function(event){  
//    var url = event.target.href;
//    if(event.target.parentNode.href) {
//		url = event.target.parentNode.href;
//    }
//    if(url && url.indexOf('http://') == 0) {
//    	if(url.indexOf("?") != -1 && (url.indexOf("/city") != -1 || url.indexOf("/list") != -1 || url.indexOf("/show") != -1)) {
//	    	post_to_url(url);
//	        event.preventDefault();  
//	        event.stopPropagation();
//    	}  
//    }  
//      
//},true);

function post_to_url(url) {
	var flag = false; // 目录到/room/show页面时是弹出新窗口，flag = false 不弹出，true是弹出
	if(url.indexOf("/room/show") != -1 && url.indexOf("?src=list") != -1){
        flag = true;
    }

    var form = document.createElement("form");
    var baseUrl = url.substring(0, url.indexOf("?"));
    var params = url.substring(url.indexOf("?") + 1, url.length);
    params = decodeURIComponent(params);
    params = params.replace("+", " ");
    var s = params.split("&");
    form.setAttribute("method", "post");
    form.setAttribute("action", baseUrl);
    for(var i = 0; i < s.length; i ++) {
        var hiddenField = document.createElement("input");
        hiddenField.setAttribute("type", "hidden");
        hiddenField.setAttribute("name", s[i].split("=")[0].replace('locationSearch', 'location'));
        hiddenField.setAttribute("value", s[i].split("=")[1]);
        form.appendChild(hiddenField);
    }
    $('body').append(form);
    if(flag){
        form.target="_blank"; // /room/show 新窗口弹出
    }
    
    form.submit();
}
</script>

<!--google analytics-->
<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-22185191-1']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>

</head>
<body>
	<div name="waitingDiv" id="waitingDiv" style="display: none;">
		<div id="list_loading" name="list_loading">
			<div id="list_loading_wrapper" class="rounded_more">
				<img src="/images/home_spinner.gif"
					style="display: block; float: left; padding: 0 12px 0 0;" />页面载入中...
			</div>
		</div>
	</div>
	<div class="header">
		<a class="logo" title="爱日租" href="/;jsessionid=0F84A550D26769620706A9DCBE383C6B"></a>
	  <div class="top_bar">
		<ul class="nav">
			
				<li>
				    <span class="SayHi"><%=Session["aliance"] != null? "嗨! " + Session["aliance"].ToString() : ""%></span>
				</li>
				
					<script type="text/javascript">

						loadUnReadMessages();
						function loadUnReadMessages(){
							$.ajax({
	   							type: "POST",
	   							url: "/ajax/userUnreadMessage",
	   							data: 1,
	   							success: function(result){
		   							$("#unReadMessages").text(result);
		   								
								}
	 						});	
						}
						//定时器
						setInterval("loadUnReadMessages()", 15000);
					
					
</script>

					<li><a href="DashBoard.aspx">用户中心</a> 
					</li>
					
					<li>
					<strong>
						<a href="/message/inbox?offset=0" class="message">
							<span id="unReadMessages"></span>
						</a>
					</strong>
					</li>
					
					<li class="rounded">
						<a href="/city?favorite=33591">
							收藏
							<span class="star" title="收藏" id="userFavorites"></span></a>
							<script type="text/javascript">

									$.ajax({
			   							type: "POST",
			   							url: "/ajax/userFavorite",
			   							data: 1,
			   							success: function(result){
				   							$("#userFavorites").text(result);
				   								
										}
			 						});
							
</script>

					</li>
				

				<li><a href="/user/logout">退出</a>
				</li>
				
			
				<li style="display:none"><span class="ChoLanguage selected">
					<a href="#none" id="language_selector_cn" onClick="shiftLanguage('zh', 'CN')">简体中文</a></span></li>
	            <li style="display:none"><span class="EngLanguage">
	            	<a href="#none" id="language_selector_en" onClick="shiftLanguage('en', 'US')">English</a></span></li>
	       <!-- 
	            <li style="font-size:20px;margin-top:-4px;">400-696-6656</li>
	      -->
			<!-- 人人网
			<li><a href="#"
				onclick="XN.Connect.requireSession(function(){window.location.href='/renren/login'});return false;">人人登录</a>
			</li>
			end-->
			<!--    <li><a>新手上路</a></li>
    <li><a>帮助</a></li>-->
			
			
		</ul>
		<a href="../SendRoom.aspx" class="btn list_your_space">
			<span>发布房间</span>
		</a>
		</div>
		<p class="customer_hot_line"><span>400-696-6656</span><a href="/media">媒体报道</a></p>
	</div>
	
	<div id="command_center">
	  <!--
	menu =>  dashboard,inbox,rooms,trips,account,recommend
 -->

<ul id="nav">
	<li id="dashboardmenu"><a href="dashboard.aspx">我爱日租</a></li>
	<li id="inboxmenu"><a href="Index.aspx">收件箱</a></li>
	<li id="roomsmenu"><a href="MyRooms.aspx">我的房间</a></li>
	<li id="tripsmenu"><a href="Trips.aspx">出行计划</a></li>
	<li id="accountmenu"><a href="Warnset.aspx">账户信息</a></li>
	<li id="commentsmenu"><a href="Comments.aspx">评价推荐</a></li>
	<li id="vouchersmenu"><a href="Vouchersinvite.aspx">赢取租币</a></li>
</ul>

	


<ul class="subnav">
	<li id="myrooms_submenu"><a href="MyRooms.aspx">所有房间</a></li>
	<li id="calendar_submenu"><a href="Calendar.aspx">日历</a></li>
	<li id="mylistings_submenu"><a href="MyListings.aspx">房间预订</a></li>
	<li id="standbys_submenu" style="display:none"><a href="/user/standbys">急需租房</a></li>
	<li id="promote_submenu" style="display:none"><a href="/user/promote">推广房间</a></li>
	<li id="pricing_submenu"><a href="Pricing.aspx">详细价格</a></li>
	<li id="policies_submenu" style="display:none"><a href="/user/policies">退款条款</a></li>
</ul>










<script type="text/javascript">

	var item=document.getElementById('roomsmenu');
	if (item){
		item.className='active';		
	}
	item=document.getElementById('calendar_submenu');
	if (item){
		item.className='active';		
	}

</script>






	  <div id="calendar">
	    <div id="left">
	      <div id="room_list" class="box">
	        <div class="top"></div>
	        <div class="middle">
	       <div class="back_to_list">
	       		<a href="MyRooms.aspx">返回房间列表</a>
	       </div>
	        
	          <ul>
	          	<%=RoomListString %>
	          </ul>
	   <!-- 
	            <div class="sub">
	            <select id="calendar_sort" >
	              <option value="">创建时间</option>
	              <option value="">名字</option>
	              <option value="">价格</option>
	              <option value="">地址</option>
	            </select>
	            <select id="calendar_filter">
	              <option value="">全部</option>
	              <option value="">开启的</option>
	              <option value="">被占领</option>
	              <option value="">签入</option>
	              <option value="">签出</option>
	            </select>
	          </div>
	  -->
	          <div class="spages"><div id="results_pagination">
				<div class="pagination">
					
				</div>
			</div></div>
	        </div>
	        <div class="bottom"></div>
	      </div>
	      <!-- romm list end -->
	    </div>
	    <!--left end-->
	    <div id="main">
	      <div id="calendar_wrapper" class="box">
	        <div class="top"></div>
	        <div class="middle" style="margin-bottom:-14px">
	          <h2 id="roomTitleId">日历 - </h2>
	          <div class="quicklinks rounded" style="display:none">
	          	<div class="links"> 
	          		<a href="#none" onclick="document.location = '/room/show/' + document.getElementById('selectedRoom').value;">查看这个房间</a>
	          		<a href="#none" onclick="document.location = '/room/edit/' + document.getElementById('selectedRoom').value;">编辑</a> 
	      <!-- 
	          		<a href="#none" onclick="document.location = '/room/show/' + document.getElementById('selectedRoom').value;">取消策略</a>
	          		<a href="">复位</a>
	   -->
	          	</div>
	            <div class="listing_status"> 订单状态
	            	<span> 
	            		<a href="">
	            			<img alt="Turn_on" src="/images/others/turn_on.png"/>
	            		</a> 
	            	</span> 
	            </div>
	            <!--listing_status end-->
	          </div>
	          <!--quicklinks end-->
	          <div id='fullcalendar'></div>
	        </div>
	        <!-- /middle -->
	        <div class="bottom"></div>
	      </div>
	      <!-- /calendar_wrapper end -->
	    </div>
	    <!-- /main （右边）-->
	    <div class="clear"></div>
	  </div>
	  <!--calendar 内容框 end-->
	</div>
	<!--command_center end-->
	
<!-- 弹出窗口 start -->	
<div class="PopBox" style="top: 40%; left: 45%; display: none;" id="pop_box_edit">
	 <div class="PMain" style="height: 230px; width: 430px;">
	     <div class="title"><h3>设置您的房间价格</h3><a class="close" onclick="$('#pop_box_edit').css('display','none');"></a></div>
	        
	        
			<div id="selectForm" style="margin-top:25px;padding: 0 20px;">
			<label class="labeltxt_b" style="float: left; width: 90px; height:35px;">请选择</label>
			<select id="unavailable" class="select_a selecttxt_l">
			<option value="false">可用</option>
			<option value="true">不可用</option>
			</select>
			<div class="clear"></div>
			<label class="labeltxt_b" style="float: left; width: 90px;">请输入价格:</label>
			<input class="input_c inputtxt_l" id="price" name="price" size="30" style="margin-right:2px;" type="text"/><span class="tip">RMB</span>
			<p><font id="tipInfo" color="red"></font></p>
			<input type="hidden" id="startDate" name="startDate"/>
			<input type="hidden" id="endDate" name="endDate"/>
			
			<input type="hidden" id="selectedRoom" name="selectedRoom" value="" />
			
			<div class="clear"></div>
			<p style="margin-top:15px; text-align:center">
			<input type="button" id="modify" name="button" value="提交" onclick="calendarsubmit()" style="padding:6px 10px;"/>
			<input type="button" name="cancel" value="取消" onclick="$('#pop_box_edit').css('display','none');" style="padding:6px 10px;"/>
			</p>
			</div>
	        
        </div>
    <div class="PopBoxBg" style="height: 238px; width: 438px;"></div>
</div>
<!-- 弹出窗口 end -->


<script type="text/javascript">
function calendarsubmit() {
	var subPrice = $("#price").val();
	$('#pop_box_edit').css('display','none');

	//alert(/^[1-9][0-9]*$/.test(subPrice) + "::" + /^[1-9][0-9]*\.[0-9]{1,2}$/.test(subPrice)){不能有空格}
	if(/^[1-9][0-9]*(\.[0-9]{1,2})?$/.test(subPrice)) {
		$.ajax({
		url: "handler/EditCalendar.ashx",
			 data:{
					price:$("#price").val(),
					startDate:$("#startDate").val(),
					endDate:$("#endDate").val(),
					roomId:$("#selectedRoom").val(),
					unavailable:$("#unavailable").val()
					},
					success:function(result) {
						var view = $('#fullcalendar').fullCalendar('getView')
						var vStart = view.visStart;
						var vEnd = view.visEnd;
						eventSource = "handler/Calendar.ashx?viewStartDate="+$.fullCalendar.formatDate(vStart, 'MM/dd/yyyy')+"&viewEndDate="+$.fullCalendar.formatDate(vEnd, 'MM/dd/yyyy')+"&roomId="+$('#selectedRoom').val();
					$('#fullcalendar').fullCalendar( 'addEventSource', eventSource );
					$('#fullcalendar').fullCalendar( 'removeEventSource', eventSource );
					
				}
			})
	}else {
		alert("请填入正确的价格");
	}
}
		</script>
	<div id='loading' style='display:none'>loading...</div>

	<!-- footer -->
	
<div id="footer">
  <p class="TxtEn">&copy; Copyright 2011 <a href="#">airizu.com 爱日租 版权所有</a>&nbsp;&nbsp;京ICP证110553 号
	 <br/>
	 <br/><img src="images/alipay.gif" width="123" height="40">&nbsp;&nbsp;
    <img src="images/tenpay.gif" width="96" height="40">&nbsp;&nbsp;    <img src="images/315.gif" width="89" height="40">    <img src="images/bluelogoair.gif"/></p>
</div>

</body>

</html>
